<?php

use Swoole\Coroutine\Http\Client;

// HTTP 客户端
class HTTPClient
{
    public function __construct($port = 9511)
    {
        go(function () use ($port) {
            $client = new Client('127.0.0.1', $port);
            $client->setHeaders([
                'Host' => 'localhost',
                'User-Agent' => 'Chrome/49.0.2587.3',
                'Accept' => 'text/html,application/xhtml+xml,application/xml',
                'Accept-Encoding' => 'gzip',
            ]);
            $client->set(['timeout' => 1]);
            $client->get('/index.php');
            echo $client->body;
            $client->close();
        });
    }

}